<template>
	<view class="page">
		<scroll-view scroll-y="true" :style="'height:'+scorllHeight+ 'px;'" @scrolltolower="loadMore">
			<view class="tab">
				<text v-for="v in tabs" :key="v.key" :class="{'tab-active' : v.key === current}" @click="tabChange(v)">
					{{v.name}}
				</text>
			</view>
			<view class="ranking">
				<view class="rangking-title">
					<text>排名</text>
					<text>店铺名称</text>
					<text>数值</text>
				</view>
				<view class="ranking-list">
					<view class="ranking-list-item" v-for="(item, key) in list" :key="key">
						<view v-if="key < 3" class="ranking-list-number">
							<image :src="`${getApp.globalData.baseImgUrl}/image/` + (key + 1) + '.png'"></image>
						</view>
						<view v-else class="ranking-list-number">
							<text>{{key + 1}}</text>
						</view>
						<view class="ranking-list-nickname">
							<image :src="item.shop_logo"></image>
							<text>{{item.supplier_name}}</text>
						</view>
						<text class="ranking-list-score">{{item.num}}</text>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import interceptor from "@/utils/request.js"
	export default {
		data() {
			return {
				current: 1,
				tabs: [{
						name: '销售额',
						key: 1
					},
					{
						name: '订单数',
						key: 2
					},
					{
						name: '销售总重',
						key: 3
					}
				],
				list: [],
				scorllHeight: 500,
				getApp:""
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res => {
					this.scorllHeight = res.windowHeight - uni.upx2px(0)
				})
			})
			this.getApp = getApp()
		},
		onShow() {
			this.getRankList()
		},
		methods: {
			tabChange(e) {
				this.current = e.key;
				this.getRankList()
			},
			getRankList(){
				this.list = []
				let params = {
					type: this.current
				}
				interceptor.get("/supplier_applet_api.php?act=rankingList", params).then((res) =>{
					this.list = res.info
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #3F51B5;
	}

	.page {
		padding-bottom: 20rpx;

		.tab {
			width: 700rpx;
			margin: auto;
			display: flex;
			justify-content: center;
			align-items: flex-end;
			padding: 25rpx;

			text {
				display: block;
				width: 140rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				color: #fff;
				font-size: 14px;
			}

			.tab-active {
				font-size: 16px;
				font-weight: bold;
				position: relative;

				&::after {
					content: '';
					width: 40rpx;
					height: 6rpx;
					border-radius: 4rpx;
					background: #fff;
					position: absolute;
					left: 40rpx;
					bottom: 0;
				}
			}

		}

		.ranking {
			width: 700rpx;
			border-radius: 30rpx;
			margin: auto;
			box-sizing: border-box;
			padding: 20rpx;

			.rangking-title {
				display: flex;
				font-size: 12px;
				color: #f0f0f0;
				height: 50rpx;
				line-height: 50rpx;

				text {
					display: block;
					width: 100rpx;
					text-align: center;

					&:nth-child(2) {
						box-sizing: border-box;
						padding-left: 20rpx;	
						width: calc(100% - 300rpx);
					}
					&:nth-child(3) {
						box-sizing: border-box;
						padding-left: 20rpx;
						width: 200rpx;
					}
				}
			}

			.ranking-list-item {
				height: 110rpx;
				border-radius: 20rpx;
				display: flex;
				align-items: center;
				font-size: 14px;
				background: rgba(255, 255, 255, 0.7);
				margin: 16rpx 0;

				&:nth-child(1) {
					background: #efb300;
				}

				&:nth-child(2) {
					background: #b4b0b0;
				}

				&:nth-child(3) {
					background: #e37d19;
				}

				.ranking-list-number {
					width: 100rpx;
					color: #777;
					display: flex;
					justify-content: center;

					image {
						width: 50rpx;
						height: 50rpx;
					}
				}

				.ranking-list-score {
					display: block;
					width: 200rpx;
					color: #555;
					font-size: 16px;
					text-align: center;
				}

				.ranking-list-nickname {
					display: flex;
					align-items: center;
					width: calc(100% - 300rpx);
					box-sizing: border-box;
					padding-left: 20rpx;

					image {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						margin-right: 20rpx;
					}

					text {
						width: auto;
					}
				}
			}
		}
	}
</style>